package com.android.jianboshi.manager;

import android.content.Context;

import com.android.baselibrary.tool.Log;
import com.android.baselibrary.tool.SPUtil;
import com.android.jianboshi.R;
import com.android.jianboshi.bean.DataInfo;
import com.android.jianboshi.constants.SPConstants;

//力量计算类
public class BoxingHelper {
    //当采样次数大于18次时，力量（公斤）=变化值/0.042。当采样次数小于等于18次时，力量（公斤）=（变化值/0.036）的1.05次方再乘以15/采样次数。采样次数小于9一律按9计算。
    public static double getPower(DataInfo air) {
        if (air.samplingTimes < 9) {
            air.samplingTimes = 9;
        }
        double power = 0;
        if (air.samplingTimes > 18) {
            power = air.airPressure / 0.042;
        } else {
            power = Math.pow((air.airPressure / 0.036), 1.05) * (15d / air.samplingTimes);
        }
        return power;
    }

    //卡路里=0.0002*力量（公斤）*体重（公斤）*次数      自由模式的卡路里用这个方法
    public static double getKCal(Context mContext, int second, int hits, double powerAvg) {
        String weightStr = SPUtil.getStringValue(mContext, SPConstants.User_Weight, "60.0");
        double weight = Double.parseDouble(weightStr);
        double kcal = 0.0002 * powerAvg * weight * hits;
        return kcal;
    }

    //卡路里=0.0001*力量（公斤）*体重（公斤）*次数      测拳速模式的卡路里计算 用这个方法
    public static double getKCal1(Context mContext, int second, int hits, double powerAvg) {
        String weightStr = SPUtil.getStringValue(mContext, SPConstants.User_Weight, "60.0");
        double weight = Double.parseDouble(weightStr);
        double kcal = 0.0001 * powerAvg * weight * hits;
        return kcal;
    }

    //根据单位转换力量
    public static double getPowerByUnit(Context mContext, double power) {
        //设置单位
        double finalPower;
        int unit = SPUtil.getIntValue(mContext, SPConstants.Unit, 0);
        if (unit == 0) {
            finalPower = power;
        } else {
            finalPower = power * 2.20462262185;
        }
        return finalPower;
    }

}
